/**
 * <copyright>
 *
 * Copyright (c) 2011 Zeligsoft (2009) Limited
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors: 
 *   Zeligsoft (2009) Limited - Initial API and implementation
 *
 * </copyright>
 *
 */
package org.omg.deployment.impl;

import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.util.FeatureMap;
import org.omg.deployment.CCMComponentPortKind;
import org.omg.deployment.DeploymentPackage;
import org.omg.deployment.DeploymentPlan;
import org.omg.deployment.InstanceDeploymentDescription;
import org.omg.deployment.PlanSubcomponentPortEndpoint;
import org.omg.xmi.impl.XMIImpl;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Plan Subcomponent Port Endpoint</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.omg.deployment.impl.PlanSubcomponentPortEndpointImpl#getPortName <em>Port Name</em>}</li>
 *   <li>{@link org.omg.deployment.impl.PlanSubcomponentPortEndpointImpl#getProvider <em>Provider</em>}</li>
 *   <li>{@link org.omg.deployment.impl.PlanSubcomponentPortEndpointImpl#getKind <em>Kind</em>}</li>
 *   <li>{@link org.omg.deployment.impl.PlanSubcomponentPortEndpointImpl#getInstance <em>Instance</em>}</li>
 *   <li>{@link org.omg.deployment.impl.PlanSubcomponentPortEndpointImpl#getInstanceRef <em>Instance Ref</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class PlanSubcomponentPortEndpointImpl extends XMIImpl implements
		PlanSubcomponentPortEndpoint {
	/**
	 * The default value of the '{@link #getPortName() <em>Port Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPortName()
	 * @generated
	 * @ordered
	 */
	protected static final String PORT_NAME_EDEFAULT = null;

	/**
	 * The default value of the '{@link #getProvider() <em>Provider</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getProvider()
	 * @generated
	 * @ordered
	 */
	protected static final String PROVIDER_EDEFAULT = null;

	/**
	 * The default value of the '{@link #getKind() <em>Kind</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getKind()
	 * @generated
	 * @ordered
	 */
	protected static final CCMComponentPortKind KIND_EDEFAULT = CCMComponentPortKind.FACET;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected PlanSubcomponentPortEndpointImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return DeploymentPackage.eINSTANCE.getPlanSubcomponentPortEndpoint();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getPortName() {
		return (String) getGroup()
				.get(DeploymentPackage.eINSTANCE
						.getPlanSubcomponentPortEndpoint_PortName(),
						true);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setPortName(String newPortName) {
		((FeatureMap.Internal) getGroup()).set(DeploymentPackage.eINSTANCE
				.getPlanSubcomponentPortEndpoint_PortName(), newPortName);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getProvider() {
		return (String) getGroup()
				.get(DeploymentPackage.eINSTANCE
						.getPlanSubcomponentPortEndpoint_Provider(),
						true);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setProvider(String newProvider) {
		((FeatureMap.Internal) getGroup()).set(DeploymentPackage.eINSTANCE
				.getPlanSubcomponentPortEndpoint_Provider(), newProvider);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public CCMComponentPortKind getKind() {
		return (CCMComponentPortKind) getGroup()
				.get(DeploymentPackage.eINSTANCE
						.getPlanSubcomponentPortEndpoint_Kind(),
						true);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setKind(CCMComponentPortKind newKind) {
		((FeatureMap.Internal) getGroup()).set(DeploymentPackage.eINSTANCE
				.getPlanSubcomponentPortEndpoint_Kind(), newKind);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public InstanceDeploymentDescription getInstance() {
		return (InstanceDeploymentDescription) getGroup()
				.get(DeploymentPackage.eINSTANCE
						.getPlanSubcomponentPortEndpoint_Instance(),
						true);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetInstance(
			InstanceDeploymentDescription newInstance, NotificationChain msgs) {
		return ((FeatureMap.Internal) getGroup()).basicAdd(
				DeploymentPackage.eINSTANCE
						.getPlanSubcomponentPortEndpoint_Instance(),
				newInstance, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setInstance(InstanceDeploymentDescription newInstance) {
		((FeatureMap.Internal) getGroup()).set(DeploymentPackage.eINSTANCE
				.getPlanSubcomponentPortEndpoint_Instance(), newInstance);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public InstanceDeploymentDescription getInstanceRef() {
		DeploymentPlan dp = null;
		InstanceDeploymentDescription result = null;

		if (this.getInstance() != null
				&& !this.getInstance().getIdref().isEmpty()) {
			for (EObject next = this; next != null && dp == null; next = next
					.eContainer()) {
				if (next instanceof DeploymentPlan) {
					dp = (DeploymentPlan) next;
				}
			}
			if (dp != null) {
				result = dp.findInstance(this.getInstance().getIdref());
			}
		}
		return result;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd,
			int featureID, NotificationChain msgs) {
		switch (featureID) {
		case DeploymentPackage.PLAN_SUBCOMPONENT_PORT_ENDPOINT__INSTANCE:
			return basicSetInstance(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
		case DeploymentPackage.PLAN_SUBCOMPONENT_PORT_ENDPOINT__PORT_NAME:
			return getPortName();
		case DeploymentPackage.PLAN_SUBCOMPONENT_PORT_ENDPOINT__PROVIDER:
			return getProvider();
		case DeploymentPackage.PLAN_SUBCOMPONENT_PORT_ENDPOINT__KIND:
			return getKind();
		case DeploymentPackage.PLAN_SUBCOMPONENT_PORT_ENDPOINT__INSTANCE:
			return getInstance();
		case DeploymentPackage.PLAN_SUBCOMPONENT_PORT_ENDPOINT__INSTANCE_REF:
			return getInstanceRef();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
		case DeploymentPackage.PLAN_SUBCOMPONENT_PORT_ENDPOINT__PORT_NAME:
			setPortName((String) newValue);
			return;
		case DeploymentPackage.PLAN_SUBCOMPONENT_PORT_ENDPOINT__PROVIDER:
			setProvider((String) newValue);
			return;
		case DeploymentPackage.PLAN_SUBCOMPONENT_PORT_ENDPOINT__KIND:
			setKind((CCMComponentPortKind) newValue);
			return;
		case DeploymentPackage.PLAN_SUBCOMPONENT_PORT_ENDPOINT__INSTANCE:
			setInstance((InstanceDeploymentDescription) newValue);
			return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
		case DeploymentPackage.PLAN_SUBCOMPONENT_PORT_ENDPOINT__PORT_NAME:
			setPortName(PORT_NAME_EDEFAULT);
			return;
		case DeploymentPackage.PLAN_SUBCOMPONENT_PORT_ENDPOINT__PROVIDER:
			setProvider(PROVIDER_EDEFAULT);
			return;
		case DeploymentPackage.PLAN_SUBCOMPONENT_PORT_ENDPOINT__KIND:
			setKind(KIND_EDEFAULT);
			return;
		case DeploymentPackage.PLAN_SUBCOMPONENT_PORT_ENDPOINT__INSTANCE:
			setInstance((InstanceDeploymentDescription) null);
			return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
		case DeploymentPackage.PLAN_SUBCOMPONENT_PORT_ENDPOINT__PORT_NAME:
			return PORT_NAME_EDEFAULT == null ? getPortName() != null
					: !PORT_NAME_EDEFAULT.equals(getPortName());
		case DeploymentPackage.PLAN_SUBCOMPONENT_PORT_ENDPOINT__PROVIDER:
			return PROVIDER_EDEFAULT == null ? getProvider() != null
					: !PROVIDER_EDEFAULT.equals(getProvider());
		case DeploymentPackage.PLAN_SUBCOMPONENT_PORT_ENDPOINT__KIND:
			return getKind() != KIND_EDEFAULT;
		case DeploymentPackage.PLAN_SUBCOMPONENT_PORT_ENDPOINT__INSTANCE:
			return getInstance() != null;
		case DeploymentPackage.PLAN_SUBCOMPONENT_PORT_ENDPOINT__INSTANCE_REF:
			return getInstanceRef() != null;
		}
		return super.eIsSet(featureID);
	}

} //PlanSubcomponentPortEndpointImpl
